package com.inwavetech.os.entity;

import com.inwavetech.os.R;
import com.inwavetech.os.util.DefaultDateFormatter;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

import java.util.Date;
import java.util.HashMap;

/**
 * Created by jgskin on 2/7/14.
 */
@DatabaseTable(tableName = "product")
public class Product {

    @DatabaseField(generatedId = true)
    public int id;

    @DatabaseField(canBeNull = false)
    public String original_id;

    @DatabaseField()
    public String name;

    @DatabaseField()
    public String identification;

    @DatabaseField()
    public String factory_warranty;

    @DatabaseField()
    public String service_warranty;

    @DatabaseField()
    public String document_code;

    @DatabaseField()
    public Date document_date;

    @DatabaseField()
    public String maintenance_type;

    @DatabaseField()
    public String maintenance_detail;

    @DatabaseField()
    public String hired_services;

    @DatabaseField()
    public String setup_detail;

    @DatabaseField(foreign = true, canBeNull = false)
    public Os os;

    @DatabaseField()
    public Diagnosys diagnosys;

    @DatabaseField()
    public String diagnosys_detail;

    @DatabaseField()
    public String installation_detail;

    @DatabaseField()
    public String installation_observation;

    public enum Diagnosys {
        ADJUST,
        BOARD_CHANGE,
        BOARD_CHANGE_NEEDED,
        POWER_CHANGE,
        POWER_CHANGE_NEEDED,
        PRODUCT_CHANGE,
        PRODUCT_CHANGE_NEEDED,
        TAG_NEAR,
        FIXATION,
        INFRA,
        RESET,
        COMPLEX,
        UNINSTALL;
    }

    public static final HashMap<Enum, Integer> diagnosysResourcesMap;

    static {
        diagnosysResourcesMap = new HashMap<Enum, Integer>();
        diagnosysResourcesMap.put(Diagnosys.ADJUST, R.string.product_diagnosys_adjust);
        diagnosysResourcesMap.put(Diagnosys.BOARD_CHANGE, R.string.product_diagnosys_board_change);
        diagnosysResourcesMap.put(Diagnosys.BOARD_CHANGE_NEEDED, R.string.product_diagnosys_board_change_needed);
        diagnosysResourcesMap.put(Diagnosys.POWER_CHANGE, R.string.product_diagnosys_power_change);
        diagnosysResourcesMap.put(Diagnosys.POWER_CHANGE_NEEDED, R.string.product_diagnosys_power_change_needed);
        diagnosysResourcesMap.put(Diagnosys.PRODUCT_CHANGE, R.string.product_diagnosys_product_change);
        diagnosysResourcesMap.put(Diagnosys.PRODUCT_CHANGE_NEEDED, R.string.product_diagnosys_product_change_needed);
        diagnosysResourcesMap.put(Diagnosys.TAG_NEAR, R.string.product_diagnosys_tag_near);
        diagnosysResourcesMap.put(Diagnosys.FIXATION, R.string.product_diagnosys_fixation);
        diagnosysResourcesMap.put(Diagnosys.INFRA, R.string.product_diagnosys_infra);
        diagnosysResourcesMap.put(Diagnosys.RESET, R.string.product_diagnosys_reset);
        diagnosysResourcesMap.put(Diagnosys.COMPLEX, R.string.product_diagnosys_complex);
        diagnosysResourcesMap.put(Diagnosys.UNINSTALL, R.string.product_diagnosys_uninstall);
    }

    public String getStringDocumentDate() {
        return DefaultDateFormatter.format(this.document_date);
    }

    public int getDiagnosysResource() throws Exception {
        if (diagnosys == null) {
            throw new Exception("no diagnosys resource");
        }

        return diagnosysResourcesMap.get(diagnosys);
    }
}
